﻿using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.Threading;

namespace DeepZoomRipperCli
{
    internal static class CommandDefinitions
    {

        public static void SetupRipCommand(Command command)
        {
            command.Description = "Download deepzoom files and save them into a Pyramid TIFF file.";

            command.AddOption(Source());
            command.AddOption(Output());
            command.AddOption(TileSize());
            command.AddOption(NoSoftwareField());

            command.Argument = new Argument<string>()
            {
                Name = "source",
                Description = "Source file location. (.dzi file)",
                Arity = ArgumentArity.ZeroOrOne
            };

            command.Handler = CommandHandler.Create<string, FileInfo, int, bool, CancellationToken>(RipActions.Rip);

            Option Source() =>
                new Option("--source", "Source file location. (.dzi file)", new Argument<string>() { Arity = ArgumentArity.ExactlyOne }, isHidden: true);

            Option Output() =>
                new Option(new[] { "--output", "--out", "-o" }, "Output TIFF file location.", new Argument<FileInfo>() { Arity = ArgumentArity.ExactlyOne });

            Option TileSize() =>
                new Option("--tile-size", "Tile size in the output TIFF. [512]",
                    new Argument<int>(512) { Arity = ArgumentArity.ExactlyOne });

            Option NoSoftwareField() =>
                new Option("--no-software-field", "Skip writting Software field. [false]",
                    new Argument<bool>(false) { Arity = ArgumentArity.ZeroOrOne });
        }

    }
}
